var app = getApp();

Page({
    data: {
        imgUrl: app.globalData.imgUrl,
        avatarUrl: app.globalData.apiHost,
        orderDet: "",
        goodsDet:"",
        orderId: "",
        orderType: "",
        latitude: "",
        longitude: "",
        markers: "",
        mapName: "",
        mapSite: "",
    },
    onLoad: function (e) {
        var that = this;
        that.setData({
            navH: app.globalData.navHeight,
            orderId: e.order_id,
            orderType: e.order_type
        })
        that.getOrderDet();
    },
    navBack: function () {
        wx.redirectTo({
            url: '../index/order-index'
        })
    },
    callPhone:function(){
        var that=this;
        wx.makePhoneCall({
            phoneNumber: app.globalData.officialPhone
        })
    },
    getLocation:function(){
        var that=this;    
        wx.getLocation({
          type: 'wgs84', 
          success: function (res) {
            wx.openLocation({
              latitude: that.data.latitude,
              longitude: that.data.longitude,
              name: that.data.mapName,
              address: that.data.mapSite
            })
          }
        })
    },
    getOrderDet: function () {
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/order/orderDetails",
            data: {
                order_id: that.data.orderId,
                order_type: that.data.orderType
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie': 'token=' + wx.getStorageSync('token')
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var detData = res.data.data;
                    var goodData = detData.goods_detail;
                    if(detData.order_type==1){
                        var hotelName = goodData.house_name;
                    }else{
                        var hotelName = goodData.name;
                    }
                    var hotelSite = goodData.province_text + goodData.city_text + goodData.area_text + goodData.address;
                    var latitudeNum = parseFloat(goodData.latitude);
                    var longitudeNum = parseFloat(goodData.longitude);
                    that.setData({
                        goodsDet: goodData,
                        orderDet: detData,
                        latitude: latitudeNum,
                        longitude: longitudeNum,
                        mapName: hotelName,
                        mapSite: hotelSite,
                        markers: [{
                            iconPath: '../../../../images/map.png',
                            id: 0,
                            latitude: latitudeNum,
                            longitude: longitudeNum,
                            width: 50,
                            height: 50
                        }],
                    })
                }
            },
            
        });
    }
})

